package com.lion.common.spring.openapi.httppack;

import io.swagger.v3.oas.models.Operation;
import org.springdoc.core.customizers.OperationCustomizer;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;

/**
 * 响应体包装注解处理器
 * 用于根据注解判断是否需要包装响应体
 */
@Component
public class ResponseWrapAnnotationProcessor implements OperationCustomizer {

    @Override
    public Operation customize(Operation operation, HandlerMethod handlerMethod) {
        // 1. 检查是否需要包装（您的注解优先级逻辑）
        boolean shouldWrapHttpResult = ResponsePackHelper.shouldWrapHttpResult(handlerMethod);
        boolean shouldWrapValueResult = ResponsePackHelper.shouldWrapValueResult(handlerMethod);

        // 2. 将结果存入Operation的扩展属性
        operation.addExtension(OpenApiConstants.X_WRAP_WITH_HTTP_RESULT, shouldWrapHttpResult);
        operation.addExtension(OpenApiConstants.X_WRAP_WITH_VALUE_RESULT, shouldWrapValueResult);

        return operation;
    }

}